package com.datasecops.scannerservices.watermark;

import com.datasecops.scannerservices.configurationfiles.WatermarkingConfiguration;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Calendar;

/**数据库水印的导入导出
 * 通用
 * @author: GeXiaoLong
 * @time: 2023/1/3 14:36
 */
@Service
@Slf4j
public class ImportAndExport {
    @Resource
    private  JNILinuxSo jniLinuxSo;
    @Resource
    private Configuration configuration;

    public  Integer text(String tableName) throws IOException, SQLException {
        log.error("水印配置参数的生成进来了吗?");
        WatermarkingConfiguration watermarkingConfiguration = new WatermarkingConfiguration();
     /*   watermarkingConfiguration.setHOST("10.26.18.61");
        watermarkingConfiguration.setPORT("3306");
        watermarkingConfiguration.setUSER("root");
        watermarkingConfiguration.setPASSWORD("sc.9102");*/
//        String DbName = "dsm";
        String OperType = "OtEmbed";
        String EmbedRableNAme = tableName;
        //换到嵌入库
        String dbname = "WatermarkingDatabase";
        String dbName = watermarkingConfiguration.getDbName()+dbname;
        watermarkingConfiguration.setDbName(dbName);

        String WmType = "WmFakeRow";
        String TraceWmEmbedChars = "DSO Database IPR, 2022.11.11, China Beijing. To:China Mobile. Usage:Collaboration, Validity:2200.12.31.";
        watermarkingConfiguration.setDBNAME("dsm");
        watermarkingConfiguration.setEMBEDTABLENAME(EmbedRableNAme);
//        String dbName = watermarkingConfiguration.getDbName()+DbName;
//        watermarkingConfiguration.setDbName(dbName);
        String operType = watermarkingConfiguration.getOperType() + OperType;
        watermarkingConfiguration.setOperType(operType);
        if ("OtEmbed".equalsIgnoreCase(OperType)) {
            String embedTableName = watermarkingConfiguration.getEmbedTableName() + EmbedRableNAme;
            watermarkingConfiguration.setEmbedTableName(embedTableName);
            String extractWmFileNameName = watermarkingConfiguration.getEmbedWmFileName() + EmbedRableNAme + ".txt";
            watermarkingConfiguration.setEmbedWmFileName(extractWmFileNameName);
            String extractAuxInfoFileName = watermarkingConfiguration.getEmbedAuxInfoFileName() + EmbedRableNAme + ".txt";
            watermarkingConfiguration.setEmbedAuxInfoFileName(extractAuxInfoFileName);
        }
        String runOutFileName = watermarkingConfiguration.getRunOutFileName() + EmbedRableNAme + ".log";
        watermarkingConfiguration.setRunOutFileName(runOutFileName);
        String tableDesFileName = watermarkingConfiguration.getTableDesFileName() + EmbedRableNAme + ".txt";
        watermarkingConfiguration.setTableDesFileName(tableDesFileName);
        String wmType = watermarkingConfiguration.getWmType() + WmType;
        watermarkingConfiguration.setWmType(wmType);
        String traceWmEmbedChars = watermarkingConfiguration.getTraceWmEmbedChars() + TraceWmEmbedChars;
        watermarkingConfiguration.setTraceWmEmbedChars(traceWmEmbedChars);
        log.error("水印配置参数的生成进来了吗?2");
        configuration.diskDropFile(watermarkingConfiguration);

        Integer text = null;
        try {
            Thread.sleep(2000);
            text = jniLinuxSo.text();
        } catch (Exception e) {
            log.error("出错了2", e);
        }

        return text;
    }


    public static void main(String[] args) throws IOException, SQLException {
        //JNILinuxSo.main();
        //JNIWinSo.text();
        // jniWinSo.text();
        //copy();
        WatermarkingConfiguration configuration = new WatermarkingConfiguration();
        ImportAndExport importAndExports = new ImportAndExport();
        //importAndExports.text(tableName);

        Calendar calendar = Calendar.getInstance();
        long time = calendar.getTimeInMillis();
        System.out.println(time);
        //exportSql(watermarkingConfiguration);
        //importSql();
        Calendar calendars = Calendar.getInstance();
        long times = calendars.getTimeInMillis();
        System.out.println(times);
        System.out.println((times-time)/1000);
    }


}
